home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / FPOUT < prev    next >
Encoding:
Text File  |  1985-12-27  |  3.4 KB  |  132 lines

  1. ;-------------------------fpout routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 104
  4. ;
  5. ; NAME  FPOUT
  6. ;
  7. ; ROUTINE FOR Conversion From Internal To External Floating Point
  8. ;
  9. ; FUNCTION: This routine displays a single precision floating point
  10. ; number on the standard output device as a decimal floating point number.
  11. ;
  12. ; INPUT: Upon entry a single precision floating point number is is SFPBUFF.
  13. ; The single precision floating point number has a 24-bit binary mantissa,
  14. ; a sign bit and an 8-bit exponent biased by 128 (Fig 5-3).
  15. ;
  16. ; OUTPUT: The individual characters of a decimal floating point number
  17. ; are sent out through the standard output device.  The decimal floating
  18. ; point number has a sign character which is blank or minus, followed by
  19. ; decimal digits of the mantissa with one embedded decimal point to the
  20. ; right of the first significant digit.  Following the mantissa is an
  21. ; exponent which starts with the letter 'E', then a sign, then a decimal
  22. ; number (Fig 5-4).
  23. ;
  24. ; REGISTERS USED:  AX, BX, CX, DX, SI and DI are modified.
  25. ;
  26. ; SEGMENTS REFERENCED:  The data segment contains storage for the variables
  27. ; DECBUFF, DECSIGN, DECEXP, FPTMP1 and SFPBUFF.
  28. ;
  29. ; ROUTINES CALLED:  STDOUT, SFP2TFP, DECHALF, DECDOUBL, DECNORM, TDECSHOW
  30. ;
  31. ; SPECIAL NOTES: Equates are used to shorten address fields.
  32. ;
  33. ; ROUTINE TO CONVERT FROM INTERNAL FLOATING POINT TO ASCII FLOATING POINT
  34. ;
  35. fpout    proc    far
  36. ;
  37.     push    di        ; save registers
  38.     push    si
  39.     push    dx
  40.     push    bx
  41.     push    cx
  42.     push    ax
  43. ;
  44. ; check for zero as a specific case
  45.     mov    ax,sfpbuffw0    ; get low word
  46.     or    ax,sfpbuffw2    ; get high word
  47.     jnz    fpout1        ; go on if not zero
  48. ;
  49.     mov    al,'0'        ; make a zero
  50.     call    stdout        ; send it out
  51.     jmp    fpout6        ; and exit
  52. ;
  53. fpout1:
  54. ; convert from single precision to temp floating point
  55.     call    sfp2tfp        ; convert to temp format
  56. ;
  57. ; initialize exponent for unnormal position
  58.     mov    decexp,21    ; exp = 21 for start
  59. ;
  60. ; set the sign
  61.     mov    al,fptemp1b10    ; get sign
  62.     mov    decsign,al    ; put it away
  63. ;
  64. ; convert a mantissa to a decimal string
  65.     lea    si,fptemp1    ; si points to fptemp1
  66.     lea    di,decbuff    ; di points to decbuff
  67.     call    bi8e2dec    ; make decimal string
  68. ;
  69. ; check sign of binary exponent
  70.     mov    cx,fptemp1w11    ; get the binary exponent
  71.     sub    cx,72        ; biased by -72
  72.     cmp    cx,0        ; check its sign
  73.     jl    fpout2        ; if negative
  74.     jg    fpout4        ; if positive
  75.     jmp    fpout5        ; if zero
  76. ;
  77. fpout2:
  78. ; binary exponent is negative
  79.     neg    cx        ; absolute value of exponent
  80. ;
  81. fpout3:
  82.     push    cx        ; save count = binary exponent
  83. ;
  84. ; divide by 2
  85.     lea    di,decbuff    ; point to decbuff
  86.     call    dechalf        ; divide by two
  87. ;
  88. ; normalize
  89.     lea    di,decbuff    ; point to decbuff
  90.     call    decnorm        ; normalize
  91. ;
  92.     pop    cx        ; restore count
  93.     loop    fpout3
  94. ;
  95.     jmp    fpout5        ; end of case
  96. ;
  97. ; binary exponent is positive
  98. ;
  99. fpout4:
  100.     push    cx        ; save count = binary exponent
  101. ;
  102. ; multiply by two
  103.     lea    di,decbuff    ; point to decbuff
  104.     call    decdoubl    ; multiply by two
  105. ;
  106. ; normalize
  107.     lea    di,decbuff    ; point to decbuff
  108.     call    decnorm        ; renormalize
  109. ;
  110.     pop    cx        ; restore count
  111.     loop    fpout4
  112. ;
  113.     jmp    fpout5        ; end of case
  114. ;
  115. fpout5:
  116. ;
  117. ; output the number
  118.     call    tdecshow    ; display the number
  119. ;
  120. fpout6:
  121.     pop    ax        ; restore registers
  122.     pop    cx
  123.     pop    bx
  124.     pop    dx
  125.     pop    si
  126.     pop    di
  127. ;
  128.     ret            ; return
  129. '
  130. fpout    endp
  131. ;-------------------------fpout routine ends---------------------------+
  132.